#!/bin/bash

## pack  files

function log() {
	echo -e "$*"
}

packname=findService
packdir=/tmp/$packname

packbins="jkstatus jkclient jksys jkimgproc jkws"
packtools="run.sh stop.sh"

log "create directory $packdir"
rm -rf $packdir
rm -rf $packdir-*.tar*
mkdir -p $packdir/{etc,bin,tools}

for i in $packbins
do
	etcname=etc/findyouwant/$i.json
	binname=../../bin/$i
	etcdir=$packdir/etc/findyouwant
	bindir=$packdir/bin
    log "do copy of $i"
	go install findService/ss/$i
	mkdir -p $etcdir
	cp -rv $etcname $etcdir
	cp -rv $binname $bindir
done

for i in $packtools
do
	log "do copy of $i"
	toolsname=tools/$i
	toolsdir=$packdir/tools
	cp -rvf $toolsname $toolsdir
done

log "pack $packname"

packtarname=$packname-`date +%Y%m%d%H%M%S`.tar.bz2

cd /tmp
tar cjvf $packtarname $packname

cd -
rm -rf $packdir

log "pack done $packname in /tmp/$packtarname"

